#!/usr/bin/env sh
set -e
name=zookeeper
[ $1 ] && name=$1

# echo "name=$name"
running=`docker ps | grep $name | awk '{print $2}'`
stoped=`docker ps -a | grep $name | awk '{print $2}'`

# echo $running
# echo $stoped
if [ $running ]
then
    echo "$name 正在运行！ \n2181：应用访问端口号 "
    exit
fi

if [ $stoped ]
then
    echo "$name 重新启动！ \n2181：应用访问端口号 "
    docker start $name > /dev/null 2>&1
    exit
fi
## 启动 zookeeper
docker run -d -p 2181:2181 --name zookeeper zookeeper:3.4 > /dev/null 2>&1
if [ $? != 0 ]
then
    echo '$name 未能正常启动！'
else
    [ `docker ps | grep $name | awk '{print $2}'` ] && echo "success! \n2181：应用访问端口号"
fi